<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->

@section('content')
<style>.layui-card-body{overflow-y: scroll;}</style>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="L_name" class="layui-form-label">
                    <span class="x-red">*</span>分类名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_name" name="name" value="{{ $data['name'] }}" required="" lay-verify="name" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <select name="status" lay-verify="required">
                        @foreach($status as $key=>$item)
                            @if($data['status']==$key)
                                <option value="{{ $key }}" selected>{{ $item }}</option>
                            @else
                                <option value="{{ $key }}">{{ $item }}</option>
                            @endif
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">提交</button></div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer','jquery'], function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            name: function(value) {
                if (value.length ==0 || value.length > 20) {
                    return '分类名称为20以内的字符';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function(data) {
            console.log(data);
            //发异步，把数据提交给php
            $.ajax({
                type: 'POST',
                url: '/admin/system/adCateEdit?id={{ $data['id'] }}',
                data: data.field,
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    // console.log(data);
                    if (data.code == 1) {
                        layer.alert("操作成功", {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else {
                        layer.alert(data.msg)
                    }
                },
                error: function (xhr, type) {
                    alert('Ajax error!')
                }
            });

            return false;
        });

    });
</script>
<script>
    layui.use('laydate',
        function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start', //指定元素
                type: 'datetime'
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end', //指定元素
                type: 'datetime'
        });
    });

</script>

@endsection
